import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import KnowledgeLayout from '@/knowledgeLayout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
const width = document.body.clientWidth
const type = width >= 500 ? 'web' : 'mobile'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/knowledgeLogin',
    component: () => import('@/views/knowledgeLogin/index'),
    hidden: true
  },
  {
    path: '/user',
    component: Layout,
    name: 'UserManager',
    children: [
      {
        path: '/userInfo',
        component: () => import('@/views/markSys/system/User/center.vue'),
        name: 'UserInfo',
        meta: { title: '个人信息' },
        hidden: true
      },
    ]
  },
  {
    path: '/screenFullWeekly',
    component: () => import('@/views/markSys/plann/screenFullWeekly/index'),
    name: 'screenFullWeekly',
    meta: { title: '周月报大屏' },
    hidden: true
  },
  {
    path: '/file-preview',
    component: () => import('@/views/markSys/components/OnlineOffice/index'),
    // redirect: '/file-preview',
    name: 'FilePreview'
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    meta: { title: '首页' },
    redirect: '/plann/calendar',
    hidden: true,
    // children: [{
    //   path: 'dashboard',
    //   name: 'Dashboard',
    //   component: () => import('@/views/dashboard/index'),
    //   meta: { title: '首页', icon: 'dashboard' }
    // }]
  }
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/home-page',
    component: Layout,
    redirect: '/home-page/index',
    name: 'HomePage',
    children: [
      {
        path: 'index',
        component: () => import('@/views/markSys/taskCenter/myTask/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/task-center',
    component: Layout,
    redirect: '/task-center/manager',
    name: 'TaskCenter',
    meta: { title: '任务中心', icon: 'example' },
    // hidden:type == 'mobile' ? true : false,
    children: [
      // {
      //   path: 'myTask',
      //   component: () => import('@/views/markSys/taskCenter/myTask/index'),
      //   name: 'MyTask',
      //   meta: { title: '我的任务' }
      // },
      {
        path: '/index-manager',
        component: () => import('@/views/markSys/index'),
        redirect: '/index-manager/list',
        name: 'IndexManager',
        meta: { title: '指标体系', roles: [ '管理员', '超级管理员'] },
        children: [
          {
            path: 'list',
            component: () => import('@/views/markSys/indexManager/showList/index'),
            name: 'List',
            meta: { title: '指标管理' }
          },
          {
            path: 'createIndex',
            component: () => import('@/views/markSys/indexManager/createIndex/create/index'),
            name: 'CreateIndex',
            hidden: true,
            meta: { title: '创建指标', activeMenu: '/index-manager/list' }
          },
          {
            path: 'edit/:id(\\d+)',
            component: () => import('@/views/markSys/indexManager/createIndex/edit/index'),
            name: 'EditIndex',
            hidden: true,
            meta: { title: '修改指标', activeMenu: '/index-manager/list' }
          },
          {
            path: 'checkIndex/:id(\\d+)',
            component: () => import('@/views/markSys/indexManager/checkTrance/indexInfo/index'),
            name: 'CheckIndex',
            meta: { title: '查阅痕迹' },
            hidden: true
          }
        ]
      },
      // {
      //   path: '/task-manager',
      //   component: () => import('@/views/markSys/index'),
      //   redirect: '/task-manager/manager',
      //   name: 'TaskCenter',
      //   meta: { title: '任务管理', icon: 'nested' },
      //   children: [
      {
        path: 'manager',
        component: () => import('@/views/markSys/taskCenter/index'),
        name: 'Manager',
        meta: { title: '我的任务' }
      },
      {
        path: 'pending',
        component: () => import('@/views/markSys/taskCenter/pendingTask/list/index'),
        name: 'PendingTask',
        meta: { title: '任务通知', noCache: true }
      },
      {
        path: 'approveList',
        component: () => import('@/views/markSys/taskCenter/approve/showList/index'),
        name: 'ApproveList',
        meta: { title: '审批通知', noCache: true }
      },
      {
        path: 'receivePageList',
        component: () => import('@/views/markSys/taskCenter/receivePageList/index'),
        name: 'ReceivePageList',
        meta: { title: '收文通知', noCache: true }
      },
      {
        path: 'infomationLetterList',
        component: () => import('@/views/markSys/taskCenter/infomationLetter/index'),
        name: 'InfomationLetters',
        meta: { title: '公告通知', noCache: true }
      },
      {
        path: 'createTask',
        component: () => import('@/views/markSys/taskCenter/PublishTask/index'),
        name: 'CreateTask',
        meta: { title: '创建普通任务', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'createFilePrint',
        component: () => import('@/views/markSys/taskCenter/PublishTask/FilePrint.vue'),
        name: 'CreateFilePrint',
        meta: { title: '创建文件审批任务', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/markSys/taskCenter/PublishTask/edit'),
        name: 'EditTask',
        meta: { title: '编辑任务', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'preview',
        component: () => import('@/views/markSys/taskCenter/previewTask/index'),
        name: 'PreviewTask',
        meta: { title: '任务预览', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'statics',
        component: () => import('@/views/markSys/taskCenter/staticsTask/index'),
        name: 'StaticsTask',
        meta: { title: '数据统计', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'report',
        component: () => import('@/views/markSys/taskCenter/pendingTask/report/index'),
        name: 'ReportTask',
        meta: { title: '填报任务', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },

      {
        path: 'question',
        component: () => import('@/views/markSys/questionRecord/index'),
        name: 'getQuestion',
        meta: { title: '问卷信息', noCache: true, activeMenu: '/task-center/manager' },
        hidden: true
      },
      {
        path: 'showRecord',
        component: () => import('@/views/markSys/taskCenter/showRecord/index'),
        name: 'ShowRecord',
        meta: { title: '表格信息', noCache: true },
        hidden: true
      },
      //   ]
      // },

      // 公文审批
      {
        path: 'handler',
        component: () => import('@/views/markSys/taskCenter/approve/handler/index'),
        name: 'HandlerPager',
        hidden: true,
        meta: { title: '处理公文', noCache: true, activeMenu: '/task-center/approveList' }
      },
      {
        path: 'recevie',
        component: () => import('@/views/markSys/taskCenter/approve/handler/recevie/index'),
        name: 'receviePager',
        hidden: true,
        meta: { title: '签收公文', noCache: true, activeMenu: '/task-center/approveList' }
      }
    ]
  },
  {
    path: '/reportMaterials',
    component: Layout,
    redirect: '/reportMaterials/index',
    name: 'ReportMaterials',
    children: [
      {
        path: 'index',
        component: () => import('@/views/markSys/reportMaterials/index'),
        name: 'Index',
        meta: { title: '事项审批', icon: 'link' }
      },
      {
        path: 'approvalPager',
        component: () => import('@/views/markSys/reportMaterials/ApprovalPager/index'),
        name: 'ApprovalPager',
        hidden: true,
        meta: { title: '上报审批', icon: 'nested' }
      },
    ]
  },
  {
    path: '/plann',
    component: Layout,
    redirect: '/plann/calendar',
    name: 'Plann',
    meta: { title: '周报月评', icon: 'table' },
    children: [
      {
        path: 'calendar',
        component: () => import('@/views/markSys/plann/calendar/index'),
        name: 'calendar',
        meta: { title: '日程' },
      },
      {
        path: 'weekly',
        component: () => import('@/views/markSys/plann/weekly/index'),
        name: 'weekly',
        meta: { title: '周报' },
      },
      {
        path: 'monthly',
        component: () => import('@/views/markSys/plann/monthly/index'),
        name: 'monthly',
        meta: { title: '月报' },
      },
      {
        path: 'yearly',
        component: () => import('@/views/markSys/plann/yearly/index'),
        name: 'yearly',
        meta: { title: '年报' },
      },
      {
        path: '/screenFullWeekly',
        redirect: '/screenFullWeekly',
        meta: { title: '周月报大屏', roles: [ '超级管理员','管理员'] },
      }
    ]
  },
  
  // {
  //   path: '/documentProcess',
  //   component: Layout,
  //   redirect: '/documentProcess/manager',
  //   meta: { title: '公文审批', icon: 'form' },
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'manager',
  //       component: () => import('@/views/markSys/documentProcess/pagesList/index'),
  //       name: 'pagersManager',
  //       meta: { title: '公文管理' }
  //     },
  //     {
  //       path: 'create',
  //       component: () => import('@/views/markSys/documentProcess/publishDocument/create/index'),
  //       name: 'CreatePager',
  //       hidden: true,
  //       meta: { title: '新建公文', noCache: true, activeMenu: '/documentProcess/manager' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/markSys/documentProcess/publishDocument/edit/index'),
  //       name: 'EditPager',
  //       hidden: true,
  //       meta: { title: '编辑公文', noCache: true, activeMenu: '/documentProcess/manager' }
  //     },
  //     {
  //       path: 'handler',
  //       component: () => import('@/views/markSys/documentProcess/publishDocument/handler/index'),
  //       name: 'HandlerPager',
  //       hidden: true,
  //       meta: { title: '处理公文', noCache: true, activeMenu: '/documentProcess/manager' }
  //     }
  //   ]
  // },
  {
    path: '/document-store',
    component: Layout,
    redirect: '/document-store/index',
    name: 'DocumentStore',
    children: [
      {
        path: 'index',
        component: () => import('@/views/markSys/documentStore/index'),
        name: 'Index',
        meta: { title: '文档中心', icon: 'nested' },
      }
    ]
  },
  {
    path: '/epidemic',
    component: Layout,
    redirect: '/document-store/index',
    name: 'epidemic',
    children:[
      {
        path:'index',
        component:  () => import('@/views/epidemic/index'),
        name:'Index',
        meta: { title: '健康监测',icon:'form',roles: [ '管理员','超级管理员'] },
      }
    ]
  },
  {
    path: '/checkinManager',
    component: Layout,
    redirect: '/checkinManager/index',
    name: 'checkinManager',
    children:[
      {
        path:'index',
        component:  () => import('@/views/checkinManager/index'),
        name:'Index',
        meta: { title: '考勤管理',icon:'location', roles: [ '超级管理员','管理员']},
      }
    ]
  },
  {
    path: '/workflow-center',
    component: Layout,
    redirect: '/workflow-center/models',
    // name: 'workflowCenter',
    meta: { title: '流程管理', icon: 'tree', roles: [ '超级管理员'] },
    // hidden:type == 'mobile' ? true : false,
    children: [
      {
        path: 'models',
        component: () => import('@/views/markSys/workflow/models/index'),
        name: 'Models',
        meta: { title: '模型管理' }
      },
      {
        path: 'processList',
        component: () => import('@/views/markSys/workflow/models/process'),
        name: 'Process',
        meta: { title: '流程定义' }
      },
      {
        path: 'processExamples',
        component: () => import('@/views/markSys/workflow/processExamples'),
        name: 'ProcessExamples',
        hidden: true,
        meta: { title: '流程实例', noCache: true, activeMenu: '/workflow-center/models' }
      }
      // {
      //   path: '/processList',
      //   component: () => import('@/views/markSys/workflow/models/process'),
      //   name: 'Process',
      //   meta: { title: '待办任务' }
      // }
    ]
  },
  {
    path: '/user-manager',
    component: Layout,
    redirect: '/user-manager/list',
    name: 'UserManager',
    meta: { title: '系统管理', icon: 'user' ,roles: [ '超级管理员','管理员']},
    // hidden:type == 'mobile' ? true : false,
    children: [
      {
        path: 'list',
        component: () => import('@/views/markSys/system/User'),
        name: 'Users',
        meta: { title: '用户管理' }
      },
      {
        path: 'department',
        component: () => import('@/views/markSys/system/department'),
        name: 'Department',
        meta: { title: '部门管理' }
      },
      {
        path: 'loginLog',
        component: () => import('@/views/markSys/system/logRecord/loginLog'),
        name: 'loginLog',
        meta: { title: '登录日志', roles: [ '超级管理员'] }
      },
      {
        path: 'errorLog',
        component: () => import('@/views/markSys/system/logRecord/errorLog'),
        name: 'errorLog',
        meta: { title: '异常日志', roles: [ '超级管理员'] }
      },
      {
        path: 'backManager',
        component: () => import('@/views/markSys/system/backManager'),
        name: 'backManager',
        meta: { title: '后台管理', roles: [ '后台管理员','超级管理员'] }
      }
    ]
  },
  {
    path: '/knowledge',
    component: KnowledgeLayout,
    redirect: '/knowledge/index',
    name: 'Knowledge',
    children: [
      {
        path: 'index',
        component: () => import('@/views/markSys/documentStore/index'),
        name: 'Index',
        meta: { title: '文档库', icon: 'nested' },
        hidden: true
      }
    ]
  },
  

 
  // {
  //   path: '/task-center',
  //   component: Layout,
  //   redirect: '/task-center/manager',
  //   name: 'Examp',
  //   meta: { title: '任务中心', icon: 'link' },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/markSys/taskCenter/index'),
  //       name: 'CreateArticle',
  //       meta: { title: 'Create Article', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/markSys/taskCenter/index'),
  //       name: 'EditArticle',
  //       meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  //       hidden: true
  //     },
  //     {
  //       path: 'manager',
  //       component: () => import('@/views/markSys/taskCenter/index'),
  //       name: 'TaskManager',
  //       meta: { title: '任务管理', icon: 'list' }
  //     }
  //   ]
  // },
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link', roles: [1, 2] }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
